//
//  HallLottery.m
//  K8彩票
//
//  Created by zhoubo on 2017/6/7.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "HallLottery.h"
#import "LotteryModel.h"
#import "HallLotteryLayout.h"
#import "HallCollectionViewCell.h"
#import "KindsSlider.h"

@interface HallLottery()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)UIView* sliderView;

@property(nonatomic,strong) UICollectionView* collectionView;

@property(nonatomic,strong)NSArray* models;



@end

@implementation HallLottery

-(void)refreshViewWithIndex:(NSInteger)index
{
    
    if (index == 0) {
        self.models = [LotteryModel getAllHallModels];
        [self.collectionView reloadData];
    }
    else if (index ==1 )
    {
        self.models = [LotteryModel getHighModels];
        [self.collectionView reloadData];
    }
    else
    {
        self.models = [LotteryModel getLowModels];
        [self.collectionView reloadData];
    }
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self setup];
        

        
        
    }
    return self;
}

-(void)setup
{

    self.models = [LotteryModel getAllHallModels];
//    HeaderView* headerView = [[HeaderView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 415)];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) collectionViewLayout:[[HallLotteryLayout alloc]initWithNum:3]];
    
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.collectionView registerClass:[HallCollectionViewCell class] forCellWithReuseIdentifier:@"hallLotteryCell"];
    
//    //注册头视图
    [self.collectionView registerClass:[KindsSlider class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"kindslider"];
    
    [self addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor colorWithWhite:248/255.0 alpha:1];
    

}




-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.models.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HallCollectionViewCell * cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"hallLotteryCell" forIndexPath:indexPath];
    
    cell.model = self.models[indexPath.row];

    
    if (indexPath.row % 2 == 0) {
        [cell setBackgroundColor:[UIColor colorWithWhite:249/255.0 alpha:1]];
    }
    else
    {
        [cell setBackgroundColor:[UIColor whiteColor]];
    }
    

    cell.backgroundColor = [UIColor colorWithRed:249/255.0 green:221/255.0 blue:220/255.0 alpha:0.5];

    
    return cell;
}


//  返回头视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    //如果是头视图
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"kindslider" forIndexPath:indexPath];
        
        
        return header;
    }
    //如果底部视图
    //    if([kind isEqualToString:UICollectionElementKindSectionFooter]){
    //
    //    }
    return nil;
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HallCollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
    NSString* title = cell.model.title;
    NSLog(@"----%@",title);
    LotteryKinds k = [LotteryModel getkindsWithTitle:title];
    switch (k) {
        case Fast3Lottery:
        {
            
            //创建一个消息对象
            NSString* info = nil;
            
            if ([title containsString:@"江苏"]) {
                info = @"jiangsufast3";
            }
            else if ([title containsString:@"湖北"])
            {
                info = @"hubeifast3";
            }
            else if ([title containsString:@"安徽"])
            {
                info = @"anhuifast3";
            }
            else
            {
                info = @"jiangsufast3";
            }
            
            
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":info}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
            
        }
            
        case Pailie3:
        {
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":@"pailie3"}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
        }
            
        case Pailie5:
        {
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":@"pailie5"}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
        }
            
            
        case Shuangse:
        {
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":@"shuangse"}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
        }
        case Daletou:
        {
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":@"daletou"}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
        }

            
            
            
        default:
        {
            //创建一个消息对象
            NSNotification * notice = [NSNotification notificationWithName:@"hallfast3" object:nil userInfo:@{@"vc":@"jiangsufast3"}];
            //发送消息
            [[NSNotificationCenter defaultCenter]postNotification:notice];
            break;
        }
            
    }
}






@end
